<?php
require_once("functions.php");
require_once("Google.php");

$g = new Google();

$keywords = $_REQUEST['keywords'];
$num = $_REQUEST['num'];
$result_mode = $_REQUEST['result_mode'];

if (empty($num) ) $num = 10;

if($num < 100)
	$g->baseurl = str_replace("num=1","num=$num",$g->baseurl);
else
	$g->baseurl = str_replace("num=1","num=100",$g->baseurl);

$search_links = array();
$total_links = 0;

if (!empty($keywords) ) {
	$temp_links = array();

	for ($i=0; $i<$num/100; $i++) {

		$start = $i * 100;

		$t2 = $g->get_links(urlencode($keywords)."&start=".$start);
		$temp_links = array_merge($temp_links,$t2);

		$total_links = $g->get_response(urlencode($keywords)."&start=".$start);
	}
	
	if ($result_mode == 'pagerank' ) {
		$search_links = $g->get_links_by_rankwise($temp_links);
	} else {
		$search_links = $temp_links;
	}
}

?>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><table width="98%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	    <td colspan="2" height="1" bgcolor="#0000CC"><img src="spacer.gif" width="1" height="1" /></td>
	</tr>
     <tr class="tr1">
        <td width="51%" height="25" align="left" style="padding-left:5px;">Showing search results in order of <?php echo $result_mode; ?></td>
        <td width="49%" align="right" style="padding-right:5px;"><?php echo number_format($total_links); ?> results found</td>
     </tr>
  </table>
</td>
  </tr>
  <tr>
    <td><table width="98%" border="0" cellspacing="5" cellpadding="0">
	  <tr>
        <td height="10"><img src="spacer.gif" width="1" height="1" /></td>
      </tr>
<?php
$count = 0;
foreach ($search_links as $link ) 
{
?>
		 <tr>
		  <td>
		   <table width="98%" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td align="left"><a href="<?php echo $link['link']; ?>" class="l"><?php echo $link['atext']; ?></a></td>
			  </tr>
			  <tr>
				<td><img src="http://pr.blogflux.com/pr3.php?s=<?php echo $link['link']; ?>" align="top" alt="Page Rank" /> (<?php echo $link['r']; ?>)</td>
			  </tr>
			  <tr>
				<td align="left" style="width:34em"><font size="-1"><?php echo $link['text']; ?></font></td>
			  </tr>
			  <tr>
				<td align="left" style="color:green"><?php echo $link['link']; ?></td>
			  </tr>
			  <tr>
				<td align="left">&nbsp;</td>
			  </tr>
			</table>
		   </td>
		  </tr>
<?php
$count++;
}
?>
    </table></td>
  </tr>
  <tr>
	<td class="tr1" height="25">&nbsp;</td>
  </tr>
  <tr>
	<td height="1" bgcolor="#0000CC"><img src="spacer.gif" width="1" height="1" /></td>
  </tr>
</table>